package com.ezops.poc.processor;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ezops.poc.dao.DataExceptionDAO;
import com.ezops.poc.validations.EzopsValidationException;

/**
 * Processor to handle the validation errors.
 * 
 * @author vgaurav
 * 
 */
@Component(value="validationErrorProcessor")
public class ValidationErrorProcessor implements Processor {

	@Autowired
	private DataExceptionDAO dao;

	/**
	 * Persis the exception which occured during validations.
	 */
	public void process(Exchange exchange) throws Exception {
		Exception exception = (Exception) exchange
				.getProperty(Exchange.EXCEPTION_CAUGHT);
		if(exception instanceof EzopsValidationException){
			dao.persist((EzopsValidationException) exception);
		}
	}

}
